
#include "lvgl.h"
#include "func_win.h"
#include "usart.h"



LV_FONT_DECLARE(major_font_30);//声明字体  标题栏
LV_FONT_DECLARE(major_font_24);//声明字体  正文
LV_FONT_DECLARE(major_font_20);//声明字体  正文
LV_FONT_DECLARE(major_font_16);//声明字体  正文


static lv_obj_t *work_win = NULL;//main_win窗口容器

//#define P3_LINE1_POINTS_NUM   (sizeof(P3_line1_points)/sizeof(P3_line1_points[0]))
//#define P3_LINE2_POINTS_NUM   (sizeof(P3_line2_points)/sizeof(P3_line2_points[0]))
//#define P3_LINE3_POINTS_NUM   (sizeof(P3_line3_points)/sizeof(P3_line3_points[0]))
//#define P3_LINE4_POINTS_NUM   (sizeof(P3_line4_points)/sizeof(P3_line4_points[0]))
//	
//#define P3_LINE5_POINTS_NUM   (sizeof(P3_line5_points)/sizeof(P3_line5_points[0]))
//#define P3_LINE6_POINTS_NUM   (sizeof(P3_line6_points)/sizeof(P3_line6_points[0]))
//#define P3_LINE7_POINTS_NUM   (sizeof(P3_line7_points)/sizeof(P3_line7_points[0]))
//#define P3_LINE8_POINTS_NUM   (sizeof(P3_line8_points)/sizeof(P3_line8_points[0]))


//const lv_point_t P3_line1_points[] = {{40,80},{280,80}};	//横线
//const lv_point_t P3_line2_points[] = {{40,160},{280,160}};
//const lv_point_t P3_line3_points[] = {{40,80},{40,160}};	//竖线
//const lv_point_t P3_line4_points[] = {{280,80},{280,160}};

//const lv_point_t P3_line5_points[] = {{40,180},{280,180}};//横线
//const lv_point_t P3_line6_points[] = {{40,340},{280,340}};
//const lv_point_t P3_line7_points[] = {{40,180},{40,340}};	//竖线
//const lv_point_t P3_line8_points[] = {{280,180},{280,340}};



//主页按键
static void P3_event_btn_h_cb(lv_event_t* e)
{
	  lv_obj_t * obj = lv_event_get_target(e);        // 获取触发事件的部件(对象)
    lv_event_code_t code = lv_event_get_code(e);    // 获取当前部件(对象)触发的事件代码

    switch(code){
        case LV_EVENT_VALUE_CHANGED:
            printf("LV_EVENT_VALUE_CHANGED\n");
            break;
				
				case LV_EVENT_RELEASED:		//按键抬起
						printf("released\r\n");			
						lv_obj_del(work_win);	//删除当前界面
						test_win_create();		//返回主界面				
						break;
				
        default:
            //printf("NONE\n");
            break;
    }
}


//菜单按键
static void P3_event_btn_m_cb(lv_event_t* e)
{
	  lv_obj_t * obj = lv_event_get_target(e);        // 获取触发事件的部件(对象)
    lv_event_code_t code = lv_event_get_code(e);    // 获取当前部件(对象)触发的事件代码

    switch(code){
        case LV_EVENT_VALUE_CHANGED:
            printf("LV_EVENT_VALUE_CHANGED\n");
            break;
				
				case LV_EVENT_RELEASED:		//按键抬起
						printf("released\r\n");			
						lv_obj_del(work_win);	//删除当前界面
						menu_win_create();		//返回菜单界面				
						break;
				
        default:
            //printf("NONE\n");
            break;
    }
}


//返回按键
static void P3_event_btn_r_cb(lv_event_t* e)
{
	  lv_obj_t * obj = lv_event_get_target(e);        // 获取触发事件的部件(对象)
    lv_event_code_t code = lv_event_get_code(e);    // 获取当前部件(对象)触发的事件代码

    switch(code){
        case LV_EVENT_VALUE_CHANGED:
            printf("LV_EVENT_VALUE_CHANGED\n");
            break;
				
				case LV_EVENT_RELEASED:			//按键抬起
						printf("released\r\n");			
						lv_obj_del(work_win);		//删除当前界面
						menu_win_create();			//返回菜单界面				
						break;
				
        default:
            //printf("NONE\n");
            break;
    }
}




//创建菜单界面
void work_win_create()
{
	printf("work win creat\r\n");
	
	static lv_style_t obj_style;
  lv_style_reset(&obj_style);
  lv_style_init(&obj_style); 					// 样式初始化
  lv_style_set_radius(&obj_style, 0); // 设置样式圆角弧度  

	work_win = lv_obj_create(lv_scr_act());  // 创建一个屏幕来模拟容器
	
	if(work_win != NULL)//创建成功
	{
		printf("work create success\r\n");
		//设置窗口特性
		lv_obj_set_style_pad_all(work_win,0,0);//padding改为0-->防止conent内缩20像素
    //lv_obj_set_style_bg_color(test_win, lv_palette_main(LV_PALETTE_NONE), 0);//不设置背景色就默认白色		
    lv_obj_set_size(work_win, 320, 480);
    lv_obj_add_style(work_win, &obj_style, 0);
		lv_obj_set_scrollbar_mode(work_win,LV_SCROLLBAR_MODE_OFF);//不显示滚动条
		


    /* 创建下方3个按键 */		
		static lv_style_t btn_style;
	  lv_style_reset(&btn_style);
		lv_style_init(&btn_style); // 样式初始化
		
    lv_obj_t * btn_h = lv_btn_create(work_win);       // 创建一个btn部件(对象),他的父对象是活动屏幕对象
		lv_obj_t * btn_m = lv_btn_create(work_win);
		lv_obj_t * btn_r = lv_btn_create(work_win);
    
		
		lv_style_set_radius(&btn_style, 5);//设置圆角
		//lv_style_set_bg_opa(&btn_style, LV_OPA_COVER);//背景透明
		lv_style_set_bg_color(&btn_style, lv_palette_lighten(LV_PALETTE_BLUE_GREY,3));//背景颜色  lv_palette_main-->调色板
		lv_style_set_border_width(&btn_style, 2);//边框
		lv_style_set_width(&btn_style,80);
		lv_style_set_height(&btn_style,50);
		
		lv_obj_set_align(btn_h,LV_ALIGN_BOTTOM_LEFT);//设置对其位置
		lv_obj_set_align(btn_m,LV_ALIGN_BOTTOM_MID);
		lv_obj_set_align(btn_r,LV_ALIGN_BOTTOM_RIGHT);
		
		//给按键添加回调函数
		lv_obj_add_event_cb(btn_h, P3_event_btn_h_cb, LV_EVENT_RELEASED, NULL);
		lv_obj_add_event_cb(btn_m, P3_event_btn_m_cb, LV_EVENT_RELEASED, NULL);
		lv_obj_add_event_cb(btn_r, P3_event_btn_r_cb, LV_EVENT_RELEASED, NULL);
				
		lv_obj_add_style(btn_h, &btn_style, 0);
		lv_obj_add_style(btn_m, &btn_style, 0);
		lv_obj_add_style(btn_r, &btn_style, 0);

		//给3个按键添加文本
		lv_obj_t *label_h = lv_label_create(btn_h); // 创建标签文本	
		lv_obj_set_style_text_font(label_h, &major_font_24, 0);        // 设置标签文本
		lv_label_set_text(label_h, "主页"); // 设置文本

		lv_obj_t *label_m = lv_label_create(btn_m); // 创建标签文本	
		lv_obj_set_style_text_font(label_m, &major_font_24, 0);        // 设置标签文本
		lv_label_set_text(label_m, "菜单"); // 设置文本
		
		lv_obj_t *label_r = lv_label_create(btn_r); // 创建标签文本	
		lv_obj_set_style_text_font(label_r, &major_font_24, 0);        // 设置标签文本
		lv_label_set_text(label_r, "返回"); // 设置文本

		//下面创建放置文本的容器框
		//设置特性
		static lv_style_t p3_text_win_style;//obj1放置文本
    lv_style_reset(&p3_text_win_style);
    lv_style_init(&p3_text_win_style); // 样式初始化
		
		//为此界面的对象放置文本的容器框统一设置样式
    lv_style_set_radius(&p3_text_win_style, 3); // 设置样式圆角弧度
    lv_style_set_bg_color(&p3_text_win_style,lv_palette_lighten(LV_PALETTE_GREY,2));//设置背景颜色
    lv_style_set_border_width(&p3_text_win_style, 2);//边框
    lv_style_set_border_color(&p3_text_win_style,lv_palette_main(LV_PALETTE_BLUE_GREY));
    lv_style_set_outline_width(&p3_text_win_style,2);//外边框
		lv_style_set_outline_color(&p3_text_win_style,lv_palette_main(LV_PALETTE_BLUE_GREY));

		lv_style_set_shadow_width(&p3_text_win_style,25);         //设置样式阴影宽度
    lv_style_set_shadow_color(&p3_text_win_style,lv_palette_main(LV_PALETTE_NONE));  //设置样式阴影颜色
    lv_style_set_shadow_ofs_x(&p3_text_win_style,5);         //设置样式x轴偏移位置
    lv_style_set_shadow_ofs_y(&p3_text_win_style,10);         //设置样式x轴偏移位置



	  lv_obj_t * p3_textwin_1 = lv_obj_create(work_win);//创建一个对象
    lv_obj_set_style_pad_all(p3_textwin_1,0,0); //padding 改为0
    lv_obj_set_scrollbar_mode(p3_textwin_1,LV_SCROLLBAR_MODE_OFF);//不显示滚动条    
    lv_obj_set_size(p3_textwin_1, 290, 40);//x,y
    lv_obj_set_pos(p3_textwin_1,10,20);//x,y
		lv_obj_add_style(p3_textwin_1, &p3_text_win_style, 0);//设置特性

	  lv_obj_t * p3_textwin_2 = lv_obj_create(work_win);//创建一个对象
    lv_obj_set_style_pad_all(p3_textwin_2,0,0); //padding 改为0
    lv_obj_set_scrollbar_mode(p3_textwin_2,LV_SCROLLBAR_MODE_OFF);//不显示滚动条    
    lv_obj_set_size(p3_textwin_2, 290, 80);//x,y
    lv_obj_set_pos(p3_textwin_2,10,80);//x,y
		lv_obj_add_style(p3_textwin_2, &p3_text_win_style, 0);//设置特性

		lv_obj_t * p3_textwin_3 = lv_obj_create(work_win);//创建一个对象
    lv_obj_set_style_pad_all(p3_textwin_3,0,0); //padding 改为0
    lv_obj_set_scrollbar_mode(p3_textwin_3,LV_SCROLLBAR_MODE_OFF);//不显示滚动条    
    lv_obj_set_size(p3_textwin_3, 290, 160);//x,y
    lv_obj_set_pos(p3_textwin_3,10,180);//x,y
		lv_obj_add_style(p3_textwin_3, &p3_text_win_style, 0);//设置特性
		
		
		
		
		
#ifdef USE_OLD	

		//创建span标题框
		static lv_style_t span_style; 				/* 定义普通样式 */
    lv_style_init(&span_style); 					/* 通样式初始化 */
    lv_style_set_border_width(&span_style, 3); /* 设置边框宽度 */    
    lv_style_set_border_color(&span_style, lv_palette_main(LV_PALETTE_BLUE_GREY)); /* 设置边框颜色 */
    lv_style_set_pad_all(&span_style, 2);
		
    lv_obj_t * spans = lv_spangroup_create(work_win); /* 创建 spans 组 */
		lv_obj_set_width(spans, 240); /* 设置该部件的宽度 */
    lv_obj_set_height(spans, 40); /* 创建该部件的高度 */
    lv_obj_align(spans,LV_ALIGN_TOP_MID,0,20);       
    lv_obj_add_style(spans, &span_style, 0);						/* 把 spans 部件添加到普通样式当中 */        
    lv_spangroup_set_align(spans, LV_TEXT_ALIGN_CENTER);/* 设置该部件的文本对齐模式 */        
    lv_spangroup_set_indent(spans, 0);									/* 设置该部件的文本缩进 */        
    lv_spangroup_set_mode(spans, LV_SPAN_MODE_BREAK);		/* 设置该部件的模式 */
   //lv_spangroup_set_overflow(spans,LV_SPAN_OVERFLOW_ELLIPSIS);
    lv_span_t * text_span = lv_spangroup_new_span(spans); 		/* 创建 spans 描述符 */
    lv_span_set_text(text_span, "工况信息 "); 									/* 设置要显示的文本 */       
    lv_style_set_text_color(&text_span->style, lv_palette_main(LV_PALETTE_NONE));/* 设置该文本的颜色 */        
    lv_style_set_text_font(&text_span->style, &major_font_30);/* 设置该文本的字体 */


		//画线
		static	lv_style_t line_style;

    lv_style_init(&line_style);                       //初始化样式
    lv_style_set_line_color(&line_style,lv_palette_main(LV_PALETTE_BLUE_GREY));//设置直线样式颜色
    lv_style_set_line_width(&line_style,3);           //设置直线样式宽度
    lv_style_set_line_rounded(&line_style,true);      //设置直线样式圆形的(末端)

    lv_obj_t * line1 = lv_line_create(work_win);  //创建直线对象
    lv_obj_t * line2 = lv_line_create(work_win);
    v_obj_t * line3 = lv_line_create(work_win);
    lv_obj_t * line4 = lv_line_create(work_win);
				
		lv_obj_t * line5 = lv_line_create(work_win);
		lv_obj_t * line6 = lv_line_create(work_win);
		lv_obj_t * line7 = lv_line_create(work_win);
		lv_obj_t * line8 = lv_line_create(work_win);

    lv_obj_add_style(line1,&line_style,0);            //将样式添加到直线
    lv_obj_add_style(line2,&line_style,0);
    lv_obj_add_style(line3,&line_style,0);
    lv_obj_add_style(line4,&line_style,0);
				
		lv_obj_add_style(line5,&line_style,0);            //将样式添加到直线
    lv_obj_add_style(line6,&line_style,0);
    lv_obj_add_style(line7,&line_style,0);
    lv_obj_add_style(line8,&line_style,0);

    lv_line_set_points(line1,P3_line1_points,P3_LINE1_POINTS_NUM);
		lv_line_set_points(line2,P3_line2_points,P3_LINE2_POINTS_NUM);
    lv_line_set_points(line3,P3_line3_points,P3_LINE3_POINTS_NUM);
    lv_line_set_points(line4,P3_line4_points,P3_LINE4_POINTS_NUM);
				
		lv_line_set_points(line5,P3_line5_points,P3_LINE5_POINTS_NUM);
    lv_line_set_points(line6,P3_line6_points,P3_LINE6_POINTS_NUM);
    lv_line_set_points(line7,P3_line7_points,P3_LINE7_POINTS_NUM);
    lv_line_set_points(line8,P3_line8_points,P3_LINE8_POINTS_NUM);
		
#endif

				//创建标签文本
				lv_obj_t *label_0 = lv_label_create(p3_textwin_1); // 创建标签文本
				lv_obj_set_style_text_font(label_0, &major_font_30, 0);        // 设置标签文本
				lv_label_set_text(label_0, "工况信息 "); // 设置文本
				//lv_obj_set_pos(label_0,40,110);
				lv_obj_align_to(label_0,p3_textwin_1,LV_ALIGN_CENTER,0,0);
				
				lv_obj_t *label_1 = lv_label_create(work_win); // 创建标签文本
				lv_obj_set_style_text_font(label_1, &major_font_24, 0);        // 设置标签文本
				lv_label_set_text(label_1, "工况选择."); // 设置文本
				lv_obj_set_pos(label_1,40,110);
				
				lv_obj_t *label_2 = lv_label_create(work_win); // 创建标签文本
				lv_obj_set_style_text_font(label_2, &major_font_24, 0);        // 设置标签文本
				lv_label_set_text(label_2, "装表距离."); // 设置文本
				lv_obj_set_pos(label_2,40,260);

        		//创建下拉列表
				lv_obj_t * dropdownlist = lv_dropdown_create(work_win);//创建下拉列表
				lv_obj_t * dd_list = lv_dropdown_get_list(dropdownlist);//获取列表对象
				lv_obj_set_pos(dropdownlist,140,100);
				lv_obj_set_style_text_font(dropdownlist, &major_font_20, 0);// 下拉列表设置新的字体
				lv_obj_set_style_text_font(dd_list, &major_font_20, 0);  //下拉列表的列表对象设置新字体
				lv_dropdown_set_options(dropdownlist, " 1. \n 2. \n 3. \n 4. ");
				//lv_dropdown_set_options(dropdownlist, " 11 \n 22 \n 33 \n 44 ");
				lv_dropdown_set_selected(dropdownlist, 0);//设置默认选项
				//lv_obj_add_event_cb(dropdownlist, dd_event_handler, LV_EVENT_ALL, NULL);//设置回调函数
		
		

	}

	

}


















